import { createStore } from 'vuex';
import {doGet} from "./request.js";
import {showMessage} from "./message.js";

export default createStore({
    state: {
        loginUser: {}
    },
    mutations: {
        setLoginUser(state, user) {
            state.loginUser = user;
        }
    },
    actions: {
        fetchUserInfo({ commit }) {
            // 假设你有一个请求函数 doGet
            doGet("/api/user/info", {}).then((resp) => {
                if (resp.data.code === 200) {
                    commit('setLoginUser', resp.data.data);
                } else {
                    showMessage("查询失败" + resp.data.msg, "error");
                }
            });
        }
    }
});